﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AmiEmuLib.Configuration;
using System.Reflection;
using System.Xml;
using System.Diagnostics;
using AmiEmuLib.AmigaConfiguration;
using AmiEmuLib.AmigaConfiguration.MemoryConfig;
using System.IO;
using AmiEmuLib.AmigaMachine.AmigaMemory;
using TomanuExtensions;

namespace AmiEmuLib.Configuration.AmigaMemoryMap
{
    /// <summary>
    /// Memory map chunk (chip, fast, etc.). Loaded from xml.
    /// </summary>
    [DebuggerDisplay("Type: {Type}, Address = {Address}, Size = {Size}")]
    public class MemoryMapChunk
    {
        /// <summary>
        /// Bank start address.
        /// </summary>
        [DebuggerDisplay("{Hex.UIntToHex(Address)}")]
        public readonly uint Address;

        /// <summary>
        /// Bank size.
        /// </summary>
        public readonly MemorySize Size;

        /// <summary>
        /// MemoryBank class name.
        /// </summary>
        public readonly MemoryBankType Type;

        /// <summary>
        /// Constructor.
        /// </summary>
        internal MemoryMapChunk(XmlReader a_reader)
        {
            Type = EnumExtensions.Parse<MemoryBankType>(a_reader.Name);
            Address = a_reader.GetAttributeHexUInt("Address");
            Size = a_reader.GetAttribute("Size");

            a_reader.MoveToNextElement(Type.ToString());
        }

        /// <summary>
        /// Last bank byte address.
        /// </summary>
        public uint LastByteAddress
        {
            get
            {
                return Address + Size - 1;
            }
        }
    }
}
